﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;

namespace Barbar.UrlGuard.Dal {
  public class MonitoringEntry : ICloneable {
    private string m_Url;
    private AuthenticationBase m_Authentication;
    private DateTime? m_LastCheckDate;
    private int m_Interval = 60;
    private int m_LastStatusCode;
    private double m_LastRequestLength;
    private string m_LastErrorMessage;
    private Guid m_Uid = Guid.NewGuid();

    public Guid Uid {
      get { return m_Uid; }
      set { m_Uid = value; }
    }

    public string Url {
      get { return m_Url; }
      set { m_Url = value; }
    }

    public string LastErrorMessage {
      get { return m_LastErrorMessage; }
      set { m_LastErrorMessage = value; }
    }

    public AuthenticationBase Authentication {
      get { return m_Authentication; }
      set { m_Authentication = value; }
    }

    public DateTime? LastCheckDate {
      get { return m_LastCheckDate; }
      set { m_LastCheckDate = value; }
    }

    public int Interval {
      get { return m_Interval; }
      set { m_Interval = value; }
    }

    public int LastStatusCode {
      get { return m_LastStatusCode; }
      set { m_LastStatusCode = value; }
    }

    public double LastRequestLength {
      get { return m_LastRequestLength; }
      set { m_LastRequestLength = value; }
    }

    public MonitoringEntryStatus Status {
      get {
        if (m_LastStatusCode == 0)
          return MonitoringEntryStatus.None;

        if (m_LastStatusCode == 200)
          return MonitoringEntryStatus.OK;

        return MonitoringEntryStatus.Error;
      }
    }

    #region ICloneable Members

    public object Clone() {
      return new MonitoringEntry() {
        Authentication = m_Authentication == null ? null : (AuthenticationBase)m_Authentication.Clone(),
        Interval = m_Interval,
        LastCheckDate = m_LastCheckDate,
        LastRequestLength = m_LastRequestLength,
        LastStatusCode = m_LastStatusCode,
        Uid = m_Uid,
        Url = m_Url
      };
    }

    #endregion
  }
}
